﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace biaoqian
{
    public partial class ADDCXSJ : Form
    {
        LDhuoyunEntities db = new LDhuoyunEntities();
        Class1 one = new Class1();
        public ADDCXSJ()
        {
            InitializeComponent();
        }

        private void ADDCXSJ_Load(object sender, EventArgs e)
        {
            GET_CYDW();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string ss = comboBox1.SelectedValue.ToString();
            int ss_id = int.Parse(ss);

            string cx_Name = textBox1.Text;
            int count = db.CXSJ.Where(x => x.cx_name == cx_Name&&x.cx_ss==ss_id).Count();
            if (count > 0)
            {
                MessageBox.Show("改承运单位下的该车型已存在，不可重复添加");
            }
            else
            {
                CXSJ cy = new CXSJ()
                {
                    cx_name = cx_Name,
                    cx_ss=ss_id,
                    cx_sh="待审核"
                };
                db.CXSJ.Add(cy);
                db.SaveChanges();
                MessageBox.Show("添加成功");
            }
        }
        private void GET_CYDW()
        {
            var item = db.CYDW.ToList();
            DataTable dataTable = one.CYDW();
            foreach (CYDW cydw in item)
            {
                dataTable.Rows.Add(cydw.cy_id, cydw.cy_name);
            }

            comboBox1.DisplayMember = "name";
            comboBox1.ValueMember = "id";
            comboBox1.DataSource = dataTable;
        }
    }
}
